<?php


/**
 * WP Showroom Admin POST Requests
 *
 * @package
 */


require_once '../../../wp-config.php';
require_once '../../../wp-admin/admin.php';
require_once 'wpsr.php';
require_once 'wpsr.admin.php';
require_once 'wpsr.file.php';
require_once 'wpsr.thumb.php';


global $user_ID;


$wpsr = new WPsrFile;
$wpsr->WPsrUser();

$path = WPSR_FILEPATH."waiting/".$user_ID."/";
$tmppath = WPSR_FILEPATH."upload/".$user_ID."/";

$event = $_POST['event'];
$redirect = '/wp-admin/admin.php?page=WPshowroom/wpsr.php';
$ext = '';

/**
 * insert new album
 */
if ($event == 'album') {
	$wpsr->addAlbum();
}


/**
 * move Album up
 */
elseif ($event == 'moveup') {
	$wpsr->moveAlbum((int) $_POST['id'], (int) $_POST['paid'], 'up');
	$ext = "&event=filter&faid=".$_POST['faid'];
}


/**
 * move Album down
 */
elseif ($event == 'movedown') {
	$wpsr->moveAlbum((int) $_POST['id'], (int) $_POST['paid'], 'down');
	$ext = "&event=filter&faid=".$_POST['faid'];
}


/**
 * edit Album
 */
elseif ($event == 'editAlbum') {
	if ($_POST['delete']) {
		$wpsr->deleteAlbum((int) $_POST['aid']);
	}
	else {
		$wpsr->editAlbum();
	}
	$ext = "&event=filter&faid=".$_POST['faid'];
}


/**
 * edit or delete Picture
 */
elseif ($event == 'editPicture') {
	if ($_POST['delete']) {
		$wpsr->deletePicture((int) $_POST['pid']);
	}
	elseif ($_POST['cover']) {
		$wpsr->AlbumCover();
	}
	else {
		$wpsr->editPicture();
	}
	$redirect = '/wp-admin/admin.php?page=WPshowroom/wpsr.php&wpsrdo=pictures&faid='. (int) $_POST['aid'];
}


/**
 * Mass edit Pictures
 */
elseif ($event == 'editPictures') {
	if ($_POST['pic'] && count($_POST['pic']) > 0) {
		if ($_POST['delete']) {
			$wpsr->deletePictures($_POST['pic']);
		}
		else {
			$wpsr->editPictures();
		}
	}
	$redirect = '/wp-admin/admin.php?page=WPshowroom/wpsr.php&wpsrdo=pictures&faid='. (int) $_POST['aid'];
}


/**
 * assign Pictures to Album
 */
elseif ($event == 'assign') {
	$wpsr->assign($user_ID, 1, $tmppath, $path, $_POST['palb'], $_POST['level']);
	$redirect = '/wp-admin/admin.php?page=WPsr-pictures';
}


/**
 * unassign Pictures from Album queue
 */
elseif ($event == 'unassign') {
	$wpsr->unassign($tmppath, $path, 9);
	$redirect = '/wp-admin/admin.php?page=WPsr-pictures';
}


/**
 * delete Pictures from Upload queue
 */
elseif ($event == 'deleteuploads') {
	$wpsr->deleteuploads($tmppath, $path, 10);
	$redirect = '/wp-admin/admin.php?page=WPsr-pictures';
}


/**
 * redirect to WPsr Admin Page
 */
$redirect = get_option('siteurl') . $redirect . '&m='.$wpsr->getMessageUrl().'&e='.$wpsr->getErrorUrl().$ext;
wp_redirect($redirect);

?>
